<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    
  </style>
</head>
<body>
  
</body>
<script>

  function P1(){
    this.a = "10";
  }
  function P2(){
    this.b = "20";
  }

  function Parent(msg){
    this.msg = msg;
    this.hahah = "heiheiei"
    this.show = function(){
      console.log(this.msg);
    }
    this.sayHi = function(){
      console.log("hi")
    }
  }
  Parent.prototype.init = function(){
    console.log("init")
  }


  function Child(abc){
    // 改变Parent内的this指向，指向Child的this
    Parent.call(this, abc);
    P1.apply(this);
    P2.bind(this)();
  }


  const p = new Parent("hello");
  console.log(p)
  p.show();
  p.sayHi();
  p.init();
  
  const c = new Child("world");
  console.log(c);
  c.show();
  c.sayHi();
  c.init();


  // new:
    // 创建新对象
    // 改变this指向这个新对象
    // ...
    // ...
    // 检测函数是否主动返回对象，如果没有，返回这个新对象


  
</script>
</html>